package com.google.code.coma.gui.dialog;

import com.google.code.coma.domain.Computer;
import com.google.code.coma.domain.Part;
import com.google.code.coma.gui.PartCellRender;
import com.google.code.coma.gui.util.ImageUtil;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.effect.Reflection;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * @author Dominik Strasser, dominikstr@gmail.com
 */
public class ComputerDialog extends Stage {
	public ComputerDialog(Computer computer) {
		if (computer == null) return;
		initModality(Modality.APPLICATION_MODAL);
		initStyle(StageStyle.UTILITY);
		setTitle("Computer " + computer.getId());
		if (computer.getOrder() != null) {
			setTitle(getTitle() + ", " + computer.getOrder().getId());
		}
		setWidth(600);
		setHeight(300);
		BorderPane border = new BorderPane();
		Scene scene = new Scene(border);
		ListView<Part> parts = new ListView<Part>();
		parts.setCellFactory(new PartCellRender());
		parts.setItems(FXCollections.<Part>observableArrayList(computer.getParts()));

		VBox partsBox = new VBox();
		partsBox.setSpacing(10);
		Label label = new Label("Parts");
		label.setFont(new Font("Arial", 18));
		partsBox.getChildren().addAll(label, parts);
		border.setLeft(partsBox);

		TableColumn<Computer.LifeCycleEntry, String> worker = new TableColumn<Computer.LifeCycleEntry, String>("Worker");
		worker.setCellValueFactory(
				new PropertyValueFactory<Computer.LifeCycleEntry, String>("worker")
		);
		worker.setMinWidth(200);
		TableColumn<Computer.LifeCycleEntry, String> date = new TableColumn<Computer.LifeCycleEntry, String>("Date");
		date.setCellValueFactory(
				new PropertyValueFactory<Computer.LifeCycleEntry, String>("date")
		);
		date.setMinWidth(70);
		TableColumn<Computer.LifeCycleEntry, String> state = new TableColumn<Computer.LifeCycleEntry, String>("State");
		state.setCellValueFactory(
				new PropertyValueFactory<Computer.LifeCycleEntry, String>("step")
		);
		state.setMinWidth(60);
		TableView<Computer.LifeCycleEntry> history = new TableView<Computer.LifeCycleEntry>();
		history.setEditable(false);
		history.getColumns().addAll(date, worker, state);
		history.setItems(FXCollections.observableArrayList(computer.getHistory()));

		VBox tableBox = new VBox();
		tableBox.setSpacing(10);
		Label label1 = new Label("History");
		label1.setFont(new Font("Arial", 18));
		tableBox.getChildren().addAll(label1, history);

		border.setCenter(tableBox);

		setScene(scene);
		show();
	}
}
